<?php

/**
 * @author guoxiaoyong
 */
namespace bc\service\wx;

use bc\model\wx\WechatAccessTokenModel;
use bc\service\base\Service;

class WechatAccessTokenService extends Service
{
	
	public function __construct()
	{
		$this->model = new WechatAccessTokenModel ();
	}
	
	/**
	 *
	 * @return array
	 */
	public function getAccessToken()
	{
		$conditionTime = time () - 7200;
		$model = $this->model;
		//$sql = 'select * from ' . $model::tableName () . ' where create_time >=' . $conditionTime . ' order by id desc';
		
		//使用ecshop的，暂用，以后不用ecshop系统时用上面的
		$sql = 'select * from wxch_config where id = 1 and dateline >=' . $conditionTime . ' limit 1';
		$row = $this->model->findBySql ( $sql )->one ();
		
		if($row['access_token'])
			return $row['access_token'];
		else
			return null;
	}
}


